import { deleteByPrimaryKeyForProUser, selectByPrimaryKeyForProUser, insertForProUser, updateForProUser, deleteByMapForProUser,updateByMapForProUser, getOneForProUser,getAllForProUser,queryPageForProUser, countForProUser, insertBatchForProUser, deleteBatchForProUser,updateBatchForProUser,getProDeptTreeByLevelCode,getProDeptTreeByParentid,getProOrgTreeByParentid,getAllAuthForUser,getAllPostForUser,queryPageForPoliceSelect,getPoliceRankTreeByParentid,getDutyLevelTreeByParentid,getWorkTreeByParentid,getChangeTypeTreeByParentid } from '@/services/business/api_policestaffselect';



export default {
    namespace: 'propoliceselect',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        selectDeptTree: {
        	list:[],
        },
        selectOrganTree: {
        	list:[],
        },
        authForUser: {
        	list:[],
        },
        postForUser: {
        	list:[],
        },
        selectPoliceRankTree: {
        	list:[],
        },
        selectDutyLevelTree: {
        	list:[],
        },
        selectWorkTree: {
        	list:[],
        },
        selectChangeTypeTree: {
        	list:[],
        },
    },

    effects: {
            *delete_by_primarykey_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProUser, payload);
								
				const newPayload = {currentPage: payload.currentPage,pageSize: payload.pageSize};
                const responsedata = yield call(queryPageForProUser, newPayload);
                yield put({
	                type: 'queryPageForProUser',
	                payload: responsedata,
                });
				if (callback) callback(response);
            },
            *select_by_primarykey_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProUser, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProUser',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(insertForProUser, payload);

                const responsedata = yield call(queryPageForProUser, {});
                yield put({
	                type: 'queryPageForProUser',
	                payload: responsedata,
                });

                if (callback) callback(response);
            },
            *update_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(updateForProUser, payload);

				const newPayload = {currentPage: payload.currentPage,pageSize: payload.pageSize};
                const responsedata = yield call(queryPageForProUser, newPayload);
                yield put({
	                type: 'queryPageForProUser',
	                payload: responsedata,
                });

                if (callback) callback(response);
            },
            *delete_by_map_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProUser, payload);
                yield put({
                    type: 'deleteByMapForProUser',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProUser, {});
                yield put({
	                type: 'queryPageForProUser',
	                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_by_map_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProUser, payload);
                yield put({
                    type: 'updateByMapForProUser',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProUser, {});
                yield put({
	                type: 'queryPageForProUser',
	                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_one_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProUser, payload);
                yield put({
                    type: 'getOneForProUser',
                    payload: response,
                });

                if (callback) callback();
            },
            *get_all_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProUser, payload);
                yield put({
                    type: 'getAllForProUser',
                    payload: response,
                });

                if (callback) callback();
            },
            *count_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(countForProUser, payload);
                yield put({
                    type: 'countForProUser',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_batch_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProUser, payload);
                yield put({
                    type: 'insertBatchForProUser',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProUser, {});
                yield put({
	                type: 'queryPageForProUser',
	                payload: responsedata,
                });


                if (callback) callback();
            },
            *delete_batch_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProUser, payload);
                yield put({
                    type: 'deleteBatchForProUser',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProUser, {});
                yield put({
	                type: 'queryPageForProUser',
	                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_batch_for_prouser({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProUser, payload);
                yield put({
                    type: 'updateBatchForProUser',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProUser, {});
                yield put({
	                type: 'queryPageForProUser',
	                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_prodepttree_by_levelcode({ payload, callback }, { call, put }) {
                const response = yield call(getProDeptTreeByLevelCode, payload);
                yield put({
                    type: 'getProDeptTreeByLevelCode',
                    payload: response,
                });

                if (callback) callback();
            },
            *get_prodepttree_by_parentid({ payload, callback }, { call, put }) {
                const response = yield call(getProDeptTreeByParentid, payload);
                yield put({
                    type: 'getProDeptTreeByParentid',
                    payload: response,
                });

                if (callback) callback(response);
            },
            *get_proorgtree_by_parentid({ payload, callback }, { call, put }) {
                const response = yield call(getProOrgTreeByParentid, payload);
                yield put({
                    type: 'getProOrgTreeByParentid',
                    payload: response,
                });

                if (callback) callback(response);
            },
            *get_all_auth_for_user({ payload, callback }, { call, put }) {
                const response = yield call(getAllAuthForUser, payload);
                yield put({
                    type: 'getAllAuthForUser',
                    payload: response,
                });

                if (callback) callback(response);
            },
            *get_all_post_for_user({ payload, callback }, { call, put }) {
                const response = yield call(getAllPostForUser, payload);
                yield put({
                    type: 'getAllPostForUser',
                    payload: response,
                });

                if (callback) callback(response);
            },
            *get_police_ranktree_by_parentid({ payload, callback }, { call, put }) {
                const response = yield call(getPoliceRankTreeByParentid, payload);
                yield put({
                    type: 'getPoliceRankTreeByParentid',
                    payload: response,
                });

                if (callback) callback(response);
            },
            *get_duty_level_tree_by_parentid({ payload, callback }, { call, put }) {
                const response = yield call(getDutyLevelTreeByParentid, payload);
                yield put({
                    type: 'getDutyLevelTreeByParentid',
                    payload: response,
                });

                if (callback) callback(response);
            },
            *get_worktree_by_parentid({ payload, callback }, { call, put }) {
                const response = yield call(getWorkTreeByParentid, payload);
                yield put({
                    type: 'getWorkTreeByParentid',
                    payload: response,
                });

                if (callback) callback(response);
            },
            *get_changetypetree_by_parentid({ payload, callback }, { call, put }) {
                const response = yield call(getChangeTypeTreeByParentid, payload);
                yield put({
                    type: 'getChangeTypeTreeByParentid',
                    payload: response,
                });

                if (callback) callback(response);
            },
            *query_page_for_policeselect({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForPoliceSelect, payload);
                yield put({
                    type: 'queryPageForPoliceSelect',
                    payload: response,
                });

                if (callback) callback();
            },
    },

    reducers: {
        deleteByPrimaryKeyForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getProDeptTreeByLevelCode(state, action) {
            return {
                ...state,
                selectDeptTree: action.payload,
            };
        },
        getProDeptTreeByParentid(state, action) {
            return {
                ...state,
                selectDeptTree: action.payload,
            };
        },
        getProOrgTreeByParentid(state, action) {
            return {
                ...state,
                selectOrganTree: action.payload,
            };
        },
        getAllAuthForUser(state, action) {
            return {
                ...state,
                authForUser: action.payload,
            };
        },
        getAllPostForUser(state, action) {
            return {
                ...state,
                postForUser: action.payload,
            };
        },
        queryPageForPoliceSelect(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getPoliceRankTreeByParentid(state, action) {
            return {
                ...state,
                selectPoliceRankTree: action.payload,
            };
        },
        getDutyLevelTreeByParentid(state, action) {
            return {
                ...state,
                selectDutyLevelTree: action.payload,
            };
        },
        getWorkTreeByParentid(state, action) {
            return {
                ...state,
                selectWorkTree: action.payload,
            };
        },
        getChangeTypeTreeByParentid(state, action) {
            return {
                ...state,
                selectChangeTypeTree: action.payload,
            };
        },
    },
};
